package com.saikei.demoapp.base

import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.databinding.ViewDataBinding

abstract class BaseInitVMFragment<VB : ViewDataBinding, VM : BaseInitVM> : BaseVMFragment<VB, VM>() {

    abstract fun initView()
    abstract fun initData()
    abstract fun initObserve()

    protected open fun getVmBr(): Int = 0
    protected open fun getPageBr(): Int = 0

    protected open fun bindViewModelAndPage() {
        try {
            mBinding.setVariable(getVmBr(), mViewModel)
            mBinding.setVariable(getPageBr(), this)
            mBinding.lifecycleOwner = this
        } catch (e: Exception) {
            Log.e("BaseInitVMActivity", "绑定失败: ${e.message}", e)
        }
    }

    override fun onFragmentCreate() {
        super.onFragmentCreate()
        bindViewModelAndPage()
        mViewModel.onLoadBundle(arguments)
        initView()
        initData()
        initObserve()
    }
}